/*
import java.util.*;

  public class TreeNode {
   int val = 0;TreeNode left = null;
   TreeNode right = null;
   public TreeNode(int val) {
    this.val = val;
   }
 }



 class Solution {
    public int[][] threeOrders (TreeNode root) {
        int[][] resList = new int[3][];
        List<Integer> list1 = new ArrayList<Integer>();
        List<Integer> list2 = new ArrayList<Integer>();
        List<Integer> list3 = new ArrayList<Integer>();

        preOrder(root,list1);
        inOrder(root,list2);
        postOrder(root,list3);

        resList[0] = new int[list1.size()];
        resList[1] = new int[list2.size()];
        resList[2] = new int[list3.size()];

        for(int i=0;i<list1.size();i++){
            resList[0][i] = list1.get(i);
            resList[1][i] = list2.get(i);
            resList[2][i] = list3.get(i);
        }
        return resList;
    }

    public void preOrder(TreeNode root,List<Integer> list){
        if(root != null){
            list.add(root.val);
            preOrder(root.left,list);
            preOrder(root.right,list);
        }
    }

    public void inOrder(TreeNode root,List<Integer> list){
        if(root != null){
            inOrder(root.left,list);
            list.add(root.val);
            inOrder(root.right,list);
        }
    }

    public void postOrder(TreeNode root,List<Integer> list){
        if(root != null){
            postOrder(root.left,list);
            postOrder(root.right,list);
            list.add(root.val);
        }
    }
}*/

/*
class Money implements Cloneable{
    public  double money =19.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person implements Cloneable{
    public int age;
    public Money m;
    public Person(int age) {
        this.age = age;
        this.m = new Money();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.m = (Money)this.m.clone();
        return tmp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}


public class Test {
    //深拷贝
    public static void main(String[] args) throws CloneNotSupportedException {
        Person p1 = new Person(10);
        Person p2 = (Person) p1.clone();
        System.out.println(p1.m.money);
        System.out.println(p2.m.money);
        p2.m.money=99.9;
        System.out.println(p1.m.money);
        System.out.println(p2.m.money);
    }
    //浅拷贝
    public static void main1(String[] args) throws CloneNotSupportedException {
        Person p1 = new Person(10);
        Person p2 = (Person) p1.clone();
        System.out.println(p1);
        System.out.println(p2);
        System.out.println(p1==p2);
    }

}*/
import User.User;

import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import User.*;
import book.BookList;

import javax.jws.soap.SOAPBinding;


/*    public static User login(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的名字");
        String name=  scanner.nextLine();
        System.out.println("请输入你的身份" +
                           "1.管理员"+
                           "2.普通用户");
        int choice =scanner.nextInt();
        if(choice==1){
            return new AdminUser(name);
        }else{
            return new NormalUser(name);
        }
    }
    public static void main(String[] args) {
        BookList bookList =new BookList();
        User user = login();
        while(true){
            int choice = user.menu();
            user.dooperation(choice,bookList);
        }
    }*/


class MyTimerTask implements Comparable<MyTimerTask> {
    private Runnable runnable;
    private long time;

    public MyTimerTask(Runnable runnable, long delay) {
        this.runnable = runnable;
        this.time = System.currentTimeMillis();
    }

    @Override
    public int compareTo(MyTimerTask o) {
        return (int) (this.time - o.time);
    }

    public long getTime() {
        return time;
    }

    public Runnable getRunnable() {
        return runnable;
    }

}


class MyTimer{
    private PriorityQueue<MyTimerTask> queue= new PriorityQueue<>();
    private Object locker = new Object();
    public void schedule(Runnable runnable,long delay){
          synchronized (locker){
           queue.offer(new MyTimerTask(runnable,delay));
           locker.notify();
          }
    }
    public MyTimer(){
        Thread t = new Thread(()->{
            while(true){
               try {
                   synchronized (locker) {
                       while (queue.isEmpty()) {
                           locker.wait();
                       }
                       MyTimerTask task = queue.peek();
                       long curTime = System.currentTimeMillis();
                       if(curTime>= task.getTime()){
                           task.getRunnable().run();
                           queue.poll();
                       }else{
                           locker.wait(task.getTime()-curTime);
                       }
                    }
                  }catch (InterruptedException e){
                   e.printStackTrace();
               }
            }
        });
        t.start();
    }
}

public class Test {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("3000");
            }
        },3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("2000");
            }
        },2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("1000");
            }
        },1000);
        System.out.println("程序启动");
    }
}
